home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap9 / encoder / encoder.pl < prev    next >
Encoding:
Perl Script  |  1996-06-15  |  864 b   |  51 lines

  1. #!/usr/local/bin/perl
  2.  
  3. require "cgilib.pl";
  4.  
  5. print "\n";
  6. print "This simple utility script takes a set of key/value pairs\n";
  7. print "and returns a CGI encoded equivilent.\n";
  8. print "Enter pairs of the form key=value.\n";
  9. print "Input will stop when you enter a blank line.\n";
  10. print "\n";
  11.  
  12. $returnString = "";
  13.  
  14. #Loop over the input
  15. while(<STDIN>)
  16. {
  17.     if(/^$/)
  18.     {
  19.         last;
  20.     }
  21.     
  22.     #Get rid of the new-line character
  23.     
  24.     chop;
  25.     
  26.     $key = "";
  27.     $value = "";
  28.     
  29.     # Break apart the key and value
  30.     
  31.     ($key,$value) = split("=",$_);
  32.     
  33.     #Add the & if this is not the first pair
  34.     
  35.     if($returnString ne "")
  36.     {
  37.         $returnString .= "&";
  38.     }
  39.     
  40.     # Append the encoded key and value
  41.     
  42.     $returnString .= &encodeData($key);
  43.     $returnString .= "=";
  44.     $returnString .= &encodeData($value);
  45.  
  46. }
  47.  
  48. print "The encoded string has: ",length($returnString)," characters\n\n";
  49. print $returnString,"\n";
  50. 1;
  51.